.TH std::chrono::operator<<(std::chrono::duration) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::chrono::operator<<(std::chrono::duration) \- std::chrono::operator<<(std::chrono::duration)

.SH Synopsis
   Defined in header <chrono>
   template<

       class CharT,
       class Traits,
       class Rep,                                                  \fI(since C++20)\fP
       class Period
   > std::basic_ostream<CharT, Traits>&
       operator<<( std::basic_ostream<CharT, Traits>& os,

                   const std::chrono::duration<Rep, Period>& d );

   Inserts a textual representation of d into os.

   Behaves as if it was implemented as

 std::basic_ostringstream<CharT, Traits> s;
 s.flags(os.flags());
 s.imbue(os.getloc());
 s.precision(os.precision());
 s << d.count() << units_suffix; // see below
 return os << s.str();

   In other words, the stream flags, locale, and precision are determined by the
   stream, but any padding are determined using the entire output string.

   The units_suffix is determined based on Period::type according to the following
   table.

   Period::type            Suffix
   std::atto               as
   std::femto              fs
   std::pico               ps
   std::nano               ns
   std::micro              µs (U+00B5) or us, it is implementation-defined which one is
                           used
   std::milli              ms
   std::centi              cs
   std::deci               ds
   std::ratio<1>           s
   std::deca               das
   std::hecto              hs
   std::kilo               ks
   std::mega               Ms
   std::giga               Gs
   std::tera               Ts
   std::peta               Ps
   std::exa                Es
   std::ratio<60>          min
   std::ratio<3600>        h
   std::ratio<86400>       d
   None of the above, and  [num]s
   Period::type::den == 1
   None of the above       [num/den]s

   For the last two rows of the table, num and den in the suffix are Period::type::num
   and Period::type::den formatted as a decimal number with no leading zeroes,
   respectively.

.SH Return value

   A reference to the stream, i.e., os.

.SH Example

   This example shows the output of std::chrono::operator<< when given a duration:


// Run this code

 #include <chrono>
 #include <iostream>
 using namespace std::chrono_literals;

 int main()
 {
     constexpr auto duration = 123ms;
     std::cout << duration << '\\n';
 }

.SH Output:

 123ms

.SH See also

   format                                stores formatted representation of the
   (C++20)                               arguments in a new string
                                         \fI(function template)\fP
   std::formatter<std::chrono::duration> formatting support for duration
   (C++20)                               \fI(class template specialization)\fP
   operator<<                            performs stream input and output on strings
   operator>>                            \fI(function template)\fP
   to_string                             converts an integral or floating-point value
   \fI(C++11)\fP                               to string
                                         \fI(function)\fP
   to_wstring                            converts an integral or floating-point value
   \fI(C++11)\fP                               to wstring
                                         \fI(function)\fP
